﻿namespace UnityEditor
{
    using System;
    using System.Runtime.CompilerServices;
    using UnityEngine;

    public sealed class VCDatabase
    {
        private static System.Action invalidateDelegate;
        private static System.Action refreshDelegate;

        private static void Call_OnInvalidate()
        {
            if (invalidateDelegate != null)
            {
                invalidateDelegate();
            }
        }

        private static void Call_OnRefresh()
        {
            if (refreshDelegate != null)
            {
                refreshDelegate();
            }
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public static extern VCAsset GetAssetByGUID(string GUID);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public static extern VCAsset GetAssetByPath(string unityPath);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        private static extern VCAsset[] Internal_GetSelected();
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public static extern void Internal_Invalidate(VCAsset[] assets);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public static extern void Internal_InvalidateAsString(string assetProjectPath);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public static extern void Invalidate();
        public static void Invalidate(UnityEngine.Object[] objects)
        {
            VCAssetList list = new VCAssetList();
            foreach (UnityEngine.Object obj2 in objects)
            {
                VCAsset assetByPath = GetAssetByPath(AssetDatabase.GetAssetOrScenePath(obj2));
                list.Add(assetByPath);
            }
            Internal_Invalidate(list.ToArray());
        }

        public static void Invalidate(VCAssetList assets)
        {
            Internal_Invalidate(assets.ToArray());
        }

        public static void InvalidateAtProjectPath(string assetProjectPath)
        {
            Internal_InvalidateAsString(assetProjectPath);
        }

        public static System.Action onInvalidate
        {
            get
            {
                return invalidateDelegate;
            }
            set
            {
                invalidateDelegate = value;
            }
        }

        public static System.Action onRefresh
        {
            get
            {
                return refreshDelegate;
            }
            set
            {
                refreshDelegate = value;
            }
        }

        public static VCAssetList selected
        {
            get
            {
                VCAssetList list = new VCAssetList();
                foreach (VCAsset asset in Internal_GetSelected())
                {
                    list.Add(asset);
                }
                return list;
            }
        }
    }
}

